package day4;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class BirDay{
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入:");
        String time = input.next();
        SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
        df.setLenient(false);
        Date d=null;
        try {
             d=df.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
            System.out.println("输入错误！");
            return;
        }
        Calendar c0=Calendar.getInstance();
        c0.setTime(d);
        if(c0.get(Calendar.MONTH)==1 &&c0.get(Calendar.DATE)==29){
            Calendar c=Calendar.getInstance();
            Calendar now=Calendar.getInstance();
            while (true){
                c.set(Calendar.DAY_OF_MONTH,1);
                c.set(c.get(Calendar.YEAR),c0.get(Calendar.MONTH),c0.get(Calendar.DATE));
                System.out.println(c.getTime());
                if(c.get(Calendar.MONTH)==1&& c.after(now))
                    break;
                c.add(Calendar.YEAR,1);

            }

            long days=(c.getTimeInMillis()-now.getTimeInMillis())/(1000*3600*24);
            System.out.println(days);
            return;
        }

        Calendar c=Calendar.getInstance();
        Calendar now=Calendar.getInstance();

        c.set(c.get(Calendar.YEAR),c0.get(Calendar.MONTH),c0.get(Calendar.DATE));
        System.out.println(c.getTime());
        //now c的之间的距离
        if(c.before(now)){
            c.add(Calendar.YEAR,1);
        }
        System.out.println("比较的时：");
        System.out.println(now.getTime()+"    "+c.getTime());
        //算now和C之间的天数
        long days=(c.getTimeInMillis()-now.getTimeInMillis())/(1000*3600*24);
        System.out.println(days);
    }
}
